load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
load("@local_config_rocm//rocm:build_defs.bzl", "if_rocm")
load("//xla:xla.default.bzl", "xla_cc_test")
load("//xla/pjrt/gpu:package_groups.bzl", "xla_gpu_internal_packages")
load("//xla/stream_executor:build_defs.bzl", "if_cuda_or_rocm")
load("//xla/tests:build_defs.bzl", "xla_test")
load("//xla/tsl:tsl.bzl", "internal_visibility")
load("//xla/tsl/platform:build_config.bzl", "tf_proto_library")
load("//xla/tsl/platform:rules_cc.bzl", "cc_library")

# Integrate with PJRT rather than the GPU client directly.
package(
    # copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
    default_visibility = [":__subpackages__"],
    licenses = ["notice"],
)

xla_gpu_internal_packages()

cc_library(
    name = "gpu_helpers",
    srcs = ["gpu_helpers.cc"],
    hdrs = ["gpu_helpers.h"],
    visibility = internal_visibility(["//xla/pjrt:friends"]),
    deps = [
        "//xla:types",
        "//xla:util",
        "//xla/client:client_library",
        "//xla/client:local_client",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_allocator_config",
        "//xla/service:platform_util",
        "//xla/stream_executor:platform",
        "//xla/stream_executor:stream_executor_h",
        "//xla/stream_executor/integrations:device_mem_allocator",
        "//xla/stream_executor/integrations:stream_executor_allocator",
        "//xla/tsl/framework:allocator",
        "//xla/tsl/framework:bfc_allocator",
        "//xla/tsl/framework:device_id_impl",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/util:env_var",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "se_gpu_pjrt_client",
    srcs = ["se_gpu_pjrt_client.cc"],
    hdrs = ["se_gpu_pjrt_client.h"],
    defines = if_cuda(["GOOGLE_CUDA=1"]) + if_rocm(["TENSORFLOW_USE_ROCM=1"]),
    visibility = internal_visibility(["//xla/pjrt/gpu:legacy_gpu_client_users"]),
    deps = [
        ":gpu_helpers",
        ":gpu_metrics",
        ":gpu_topology",
        ":gpu_topology_proto_cc",
        ":se_gpu_topology_description",
        "//xla:executable_run_options",
        "//xla:literal",
        "//xla:shape_tree",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla:xla_proto_cc",
        "//xla/backends/gpu/collectives:gpu_clique_key",
        "//xla/backends/gpu/collectives:gpu_cliques",
        "//xla/backends/gpu/collectives:gpu_collectives",
        "//xla/client:client_library",
        "//xla/client:local_client",
        "//xla/core/collectives",
        "//xla/core/collectives:clique_id",
        "//xla/core/collectives:collectives_registry",
        "//xla/core/collectives:communicator",
        "//xla/core/collectives:rank_id",
        "//xla/hlo/builder:xla_computation",
        "//xla/pjrt:device_event",
        "//xla/pjrt:event_pool",
        "//xla/pjrt:host_memory_spaces",
        "//xla/pjrt:local_device_state",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_common",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_description",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt:pjrt_future",
        "//xla/pjrt:pjrt_stream_executor_client",
        "//xla/pjrt:stream_executor_executable",
        "//xla/pjrt:stream_executor_executable_proto_cc",
        "//xla/pjrt:utils",
        "//xla/pjrt:worker_thread",
        "//xla/pjrt/distributed:client",
        "//xla/pjrt/distributed:in_memory_key_value_store",
        "//xla/pjrt/distributed:key_value_store_interface",
        "//xla/pjrt/distributed:topology_util",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_allocator_config",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/pjrt/proto:compile_options_proto_cc",
        "//xla/runtime:device_id",
        "//xla/service:buffer_assignment",
        "//xla/service:compiler",
        "//xla/service:computation_placer_hdr",
        "//xla/service:executable",
        "//xla/service:global_device_id",
        "//xla/service:platform_util",
        "//xla/service:shaped_buffer",
        "//xla/service:transfer_manager",
        "//xla/service/gpu:gpu_executable_run_options",
        "//xla/stream_executor:device_description",
        "//xla/stream_executor:device_memory",
        "//xla/stream_executor:device_memory_allocator",
        "//xla/stream_executor:platform",
        "//xla/stream_executor:stream",
        "//xla/stream_executor:stream_executor_h",
        "//xla/stream_executor/cuda:cuda_compute_capability",
        "//xla/stream_executor/integrations:device_mem_allocator",
        "//xla/stream_executor/integrations:tf_allocator_adapter",
        "//xla/tsl/concurrency:async_value",
        "//xla/tsl/concurrency:ref_count",
        "//xla/tsl/distributed_runtime/coordination:coordination_service",
        "//xla/tsl/distributed_runtime/coordination:coordination_service_agent",
        "//xla/tsl/framework:allocator",
        "//xla/tsl/framework:bfc_allocator",
        "//xla/tsl/framework:device_id",
        "//xla/tsl/framework:device_id_impl",
        "//xla/tsl/lib/strings:proto_serialization",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:status",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/protobuf:coordination_service_proto_cc",
        "//xla/tsl/util:env_var",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:inlined_vector",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/functional:bind_front",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@llvm-project//mlir:IR",
        "@tsl//tsl/platform:casts",
        "@tsl//tsl/platform:env",
        "@tsl//tsl/platform:errors",
        "@tsl//tsl/platform:fingerprint",
        "@tsl//tsl/platform:protobuf",
        "@tsl//tsl/platform:status",
        "@tsl//tsl/platform:statusor",
        "@tsl//tsl/profiler/lib:connected_traceme",
        "@tsl//tsl/profiler/lib:nvtx_utils",
        "@tsl//tsl/profiler/lib:traceme",
    ] + if_cuda_or_rocm([
        # keep sorted
        "//xla:debug_options_flags",
        "//xla/service/gpu:gpu_compiler",
        "//xla/service/gpu:gpu_constants",
        "//xla/service/gpu:gpu_executable",
        "//xla/service/gpu:gpu_memory_space_assignment",
        "//xla/service/gpu:stream_executor_util",
    ]) + if_cuda([
        # keep sorted
        "//xla/service/gpu/model:gpu_collective_performance_model",
        "//xla/stream_executor/gpu:gpu_cudamallocasync_allocator",
        "//xla/stream_executor/gpu:gpu_stream",
        "@local_config_cuda//cuda:cuda_headers",
    ]) + if_rocm([
        # keep sorted
        "@local_config_rocm//rocm:rocm_headers",
    ]),
)

xla_test(
    name = "se_gpu_pjrt_client_test",
    srcs = ["se_gpu_pjrt_client_test.cc"],
    backend_tags = {"gpu": [
        "multi_gpu_h100",
        "no_oss",
        "noasan",
        "nomsan",
    ]},
    backends = ["gpu"],
    deps = [
        ":gpu_topology",
        ":gpu_topology_proto_cc",
        ":se_gpu_pjrt_client",
        ":se_gpu_topology_description",
        "//xla:debug_options_flags",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla:xla_proto_cc",
        "//xla/ffi",
        "//xla/ffi:ffi_api",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/parser:hlo_parser",
        "//xla/hlo/testlib:test",
        "//xla/pjrt:host_memory_spaces",
        "//xla/pjrt:local_device_state",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_description",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt:pjrt_future",
        "//xla/pjrt:pjrt_stream_executor_client",
        "//xla/pjrt:raw_buffer",
        "//xla/pjrt/distributed",
        "//xla/pjrt/distributed:client",
        "//xla/pjrt/distributed:in_memory_key_value_store",
        "//xla/pjrt/distributed:service",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/pjrt/profiling:device_time_measurement",
        "//xla/pjrt/profiling/test_util:mock_device_time_measurement",
        "//xla/pjrt/proto:compile_options_proto_cc",
        "//xla/service:platform_util",
        "//xla/service/gpu:gpu_memory_space_assignment",
        "//xla/stream_executor:device_memory",
        "//xla/stream_executor:stream",
        "//xla/stream_executor/cuda:cuda_compute_capability",
        "//xla/tests:literal_test_util",
        "//xla/tsl/lib/core:status_test_util",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:status",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:subprocess",
        "//xla/tsl/util:command_line_flags",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest",
        "@llvm-project//mlir:IR",
        "@tsl//tsl/platform",
        "@tsl//tsl/platform:casts",
        "@tsl//tsl/platform:platform_port",
        "@tsl//tsl/platform:protobuf",
    ],
)

xla_test(
    name = "se_gpu_pjrt_client_benchmark_test",
    srcs = ["se_gpu_pjrt_client_benchmark_test.cc"],
    backends = ["gpu"],
    deps = [
        ":se_gpu_pjrt_client",
        "//xla:xla_data_proto_cc",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_allocator_config",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/tsl/platform:test",
        "//xla/tsl/platform:test_benchmark",
        "//xla/tsl/platform:test_main",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/strings:string_view",
        "@llvm-project//mlir:IR",
    ],
)

xla_test(
    name = "nvshmem_gpu_collectives_test",
    srcs = ["nvshmem_gpu_collectives_test.cc"],
    backend_tags = {"gpu": [
        "multi_gpu_h100",
        "no_oss",
        "noasan",
        "nomsan",
    ]},
    backends = ["gpu"],
    env = {
        "XLA_FLAGS": "--xla_gpu_experimental_enable_nvshmem=true",
    },
    deps = [
        ":gpu_topology",
        ":se_gpu_pjrt_client",
        "//xla:debug_options_flags",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla:types",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/ffi",
        "//xla/ffi:ffi_api",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/parser:hlo_parser",
        "//xla/hlo/testlib:test",
        "//xla/pjrt:host_memory_spaces",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt:pjrt_future",
        "//xla/pjrt:pjrt_stream_executor_client",
        "//xla/pjrt/distributed",
        "//xla/pjrt/distributed:client",
        "//xla/pjrt/distributed:in_memory_key_value_store",
        "//xla/pjrt/distributed:service",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/service:platform_util",
        "//xla/stream_executor:device_memory",
        "//xla/stream_executor:stream",
        "//xla/tests:literal_test_util",
        "//xla/tsl/lib/core:status_test_util",
        "//xla/tsl/platform:env",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:status",
        "//xla/tsl/platform:status_matchers",
        "//xla/tsl/platform:statusor",
        "//xla/tsl/platform:subprocess",
        "//xla/tsl/util:command_line_flags",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest",
        "@llvm-project//mlir:IR",
    ],
)

# TODO(b/409713313): Move this test to collectives directory.
xla_test(
    name = "se_gpu_pjrt_client_nvshmem_test",
    srcs = ["se_gpu_pjrt_client_nvshmem_test.cc"],
    backend_tags = {"gpu": [
        "multi_gpu_h100",
        "no_oss",
        "noasan",
        "nomsan",
    ]},
    backends = ["gpu"],
    env = {
        "XLA_FLAGS": "--xla_gpu_experimental_enable_nvshmem=true",
    },
    deps = [
        ":gpu_topology_proto_cc",
        ":se_gpu_pjrt_client",
        "//xla:shape_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla:xla_proto_cc",
        "//xla/backends/gpu/collectives:gpu_collectives",
        "//xla/ffi",
        "//xla/ffi:ffi_api",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/parser:hlo_parser",
        "//xla/hlo/testlib:test",
        "//xla/hlo/utils:hlo_query",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt:raw_buffer",
        "//xla/pjrt/distributed",
        "//xla/pjrt/distributed:client",
        "//xla/pjrt/distributed:in_memory_key_value_store",
        "//xla/pjrt/distributed:service",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/service:platform_util",
        "//xla/tests:literal_test_util",
        "//xla/tsl/lib/core:status_test_util",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:span",
    ],
)

xla_test(
    name = "pjrt_client_test_se_gpu",
    srcs = ["pjrt_client_test_se_gpu.cc"],
    backend_tags = {
        "gpu": ["multi_gpu"],
    },
    backends = ["gpu"],
    tags = [
        "no_oss",
        "notap",
    ],
    deps = [
        ":se_gpu_pjrt_client",
        "//xla/pjrt:pjrt_client_test_common",
        "@com_google_googletest//:gtest_main",
    ],
)

tf_proto_library(
    name = "gpu_topology_proto",
    srcs = ["gpu_topology.proto"],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "gpu_topology",
    srcs = ["gpu_topology.cc"],
    hdrs = ["gpu_topology.h"],
    visibility = internal_visibility([
        "//xla/pjrt/gpu:legacy_gpu_topology_users",
        ":__subpackages__",
    ]),
    deps = [
        ":gpu_topology_proto_cc",
        "@com_google_absl//absl/strings:string_view",
    ],
)

cc_library(
    name = "se_gpu_pjrt_compiler_impl",
    srcs = ["se_gpu_pjrt_compiler.cc"],
    hdrs = ["se_gpu_pjrt_compiler.h"],
    deps = [
        ":se_gpu_pjrt_client",
        ":se_gpu_topology_description",
        "//xla:shape_util",
        "//xla:status_macros",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/ir:hlo",
        "//xla/hlo/ir:hlo_module_group",
        "//xla/pjrt:mlir_to_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt:stream_executor_executable",
        "//xla/pjrt:utils",
        "//xla/service:compiler",
        "//xla/service:dump",
        "//xla/service:hlo_module_config",
        "//xla/service:hlo_module_util",
        "//xla/service:hlo_proto_cc",
        "//xla/service:local_service_utils",
        "//xla/service:platform_util",
        "//xla/service/gpu:executable_proto_cc",
        "//xla/stream_executor:platform",
        "//xla/stream_executor:platform_manager",
        "//xla/tsl/platform:errors",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@llvm-project//mlir:IR",
        "@tsl//tsl/platform:casts",
    ],
)

cc_library(
    name = "se_gpu_pjrt_compiler_cuda_registration",
    srcs = ["se_gpu_pjrt_compiler_cuda_registration.cc"],
    compatible_with = [],
    tags = [
        "cuda-only",
        "gpu",
    ],
    deps = [
        ":se_gpu_pjrt_compiler_impl",
        "//xla/pjrt:pjrt_compiler",
        "//xla/service/gpu:nvptx_compiler",  # buildcleaner: keep
        "//xla/stream_executor/cuda:cuda_platform_id",
        "//xla/stream_executor/platform:initialize",
    ],
    alwayslink = 1,
)

cc_library(
    name = "se_gpu_pjrt_compiler_rocm_registration",
    srcs = ["se_gpu_pjrt_compiler_rocm_registration.cc"],
    compatible_with = [],
    tags = [
        "gpu",
        "rocm-only",
    ],
    deps = [
        ":se_gpu_pjrt_compiler_impl",
        "//xla/pjrt:pjrt_compiler",
        "//xla/service/gpu:amdgpu_compiler",  # buildcleaner: keep
        "//xla/stream_executor/platform:initialize",
        "//xla/stream_executor/rocm:rocm_platform_id",
    ],
    alwayslink = 1,
)

cc_library(
    name = "se_gpu_pjrt_compiler",
    hdrs = ["se_gpu_pjrt_compiler.h"],
    # TODO(b/382070262): Migrate users off this target - They should go though the PjRt ABI compatibility layer.
    visibility = internal_visibility(["//xla/pjrt/gpu:legacy_se_gpu_pjrt_compiler_users"]),
    deps = [
        ":se_gpu_pjrt_compiler_impl",
        "//xla/hlo/builder:xla_computation",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_executable",
        "//xla/service:compiler",
        "//xla/stream_executor:platform",
        "@com_google_absl//absl/status:statusor",
        "@llvm-project//mlir:IR",
    ] + if_cuda([
        ":se_gpu_pjrt_compiler_cuda_registration",
    ]) + if_rocm([
        ":se_gpu_pjrt_compiler_rocm_registration",
    ]),
)

cc_library(
    name = "gpu_metrics",
    srcs = ["gpu_metrics.cc"],
    hdrs = ["gpu_metrics.h"],
    visibility = ["//visibility:public"],
    deps = [
        "//xla/tsl/lib/monitoring:gauge",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:string_view",
    ],
)

xla_test(
    name = "se_gpu_pjrt_compiler_test",
    srcs = ["se_gpu_pjrt_compiler_test.cc"],
    backends = ["gpu"],
    deps = [
        ":gpu_topology",
        ":se_gpu_pjrt_client",
        ":se_gpu_pjrt_compiler_impl",
        ":se_gpu_topology_description",
        "//xla:literal",
        "//xla:literal_util",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/parser:hlo_parser",
        "//xla/hlo/testlib:test",
        "//xla/mlir_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/tests:literal_test_util",
        "//xla/tsl/platform:status_matchers",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:status_matchers",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Parser",
    ],
)

xla_test(
    name = "se_gpu_pjrt_compiler_aot_test",
    srcs = ["se_gpu_pjrt_compiler_aot_test.cc"],
    backends = ["gpu"],
    deps = [
        ":se_gpu_pjrt_client",
        ":se_gpu_pjrt_compiler_impl",
        "//xla:literal",
        "//xla:literal_util",
        "//xla:xla_data_proto_cc",
        "//xla/hlo/builder:xla_computation",
        "//xla/hlo/parser:hlo_parser",
        "//xla/mlir_hlo",
        "//xla/pjrt:pjrt_client",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_executable",
        "//xla/pjrt/plugin/xla_gpu:xla_gpu_client_options",
        "//xla/service:compiler",
        "//xla/tests:literal_test_util",
        "//xla/tsl/platform:statusor",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Parser",
        "@tsl//tsl/platform:casts",
    ],
)

cc_library(
    name = "se_gpu_topology_description",
    srcs = ["se_gpu_topology_description.cc"],
    hdrs = ["se_gpu_topology_description.h"],
    visibility = internal_visibility([
        "//xla/pjrt/gpu:legacy_gpu_topology_users",
        ":__subpackages__",
    ]),
    deps = [
        ":gpu_topology",
        "//xla:shape_util",
        "//xla:xla_data_proto_cc",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_description",
        "//xla/pjrt:pjrt_stream_executor_device_description",
        "//xla/stream_executor:device_description_proto_cc",
        "//xla/tsl/lib/strings:proto_serialization",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/types:span",
    ],
)

xla_cc_test(
    name = "se_gpu_topology_description_test",
    srcs = ["se_gpu_topology_description_test.cc"],
    deps = [
        ":gpu_topology",
        ":se_gpu_topology_description",
        "//xla/pjrt:pjrt_compiler",
        "//xla/pjrt:pjrt_device_description",
        "//xla/pjrt:pjrt_stream_executor_device_description",
        "@com_google_googletest//:gtest_main",
    ],
)
